Advanced Code Block
DevAssure provides the capability to execute custom JavaScript code during your test runs.
This feature allows you to perform complex validations and seamlessly integrate custom code logic tailored to your test cases.
- Navigate to the Editor view of the test case and hover over the test step where you wish to insert the code block. Then, select Add Advanced Code Block or choose Add Code Block to append code after the preceding test step.

-
To access DevAssure Test Actions within the code block, start typing "::" . This will trigger a list of suggestions for available functions to help you complete the code.
-
The test data and constants can also be referenced inside the code block.

- Example 1 : Below illustrates a simple JavaScript code block demonstrating how to clear the quantity of items, update the quantity with test data values, and verify the functionality of adding items to a cart on an e-commerce website.

- Example 2 : Additionally, presented here is another example of Java script code block showcasing the generation of random email IDs, which can be utilized in login test cases.

-
Example 3 : This code block is designed to iterate through a list of flights, check if a "lowest fare" tag is present for each flight, and conditionally perform actions based on that presence. If the lowest fare tag is found, it logs the flight price and then selects that particular flight.
-
Prerequisites
- A variable named
Noofflights
which holds the total number of flights to iterate through. This variable must be defined and accessible before this code block executes. - Defined page objects/locators for:
FlightSearch-SearchFlightTimings_Prices_AkasaAir
: The parent container or section for flight timings and prices.Flightprice
: The element containing the price for an individual flight.Flighttag_low_price
: The element representing the "lowest fare" tag.FlightSelect
: The element used to select an individual flight.
- A variable named

# verify if the lowest fare tag is present
for (let i=0; i<Noofflights; i++) {
flightPrice = Get text of web > FlightSearch-SearchFlightTimings_Prices_AkasaAir > Flightprice ( count: ${i} )
isPresent_0 = Is element web > FlightSearch-SearchFlightTimings_Prices_AkasaAir > Flighttag_low_price ( count: ${i} ) present within 1000 milliseconds
if (isPresent_0) {
Print log flightPrice
Click on web > FlightSearch-SearchFlightTimings_Prices_AkasaAir > FlightSelect ( count: ${i} )
}
}
Print log "Lowest Fare Tag is not present"
- For passing dynamic values to elements referenced in code block, please refer to the documentation here.